package com.huluobo.mvvm_base.view;

import android.graphics.Color;
import android.os.Bundle;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.databinding.DataBindingUtil;
import androidx.databinding.ViewDataBinding;
import androidx.lifecycle.ViewModelProvider;

import com.huluobo.mvvm_base.event.CustomEvent;
import com.huluobo.mvvm_base.viewmodel.BaseViewModel;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

/**
 * Created by LC on 2024/3/22.
 */
public abstract class BaseMVVMActivity<VDB extends ViewDataBinding, VM extends BaseViewModel> extends AppCompatActivity {
    //视图绑定
    protected VDB dataBinding;

    //对应的ViewModel
    protected VM viewModel;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //1.绑定视图
        dataBinding = DataBindingUtil.setContentView(this, getLayoutId());
        //2.实例化对应的ViewModel
        viewModel = new ViewModelProvider(this).get(getViewModel());
        initView();
        initData();
        //注册事件总线
        EventBus.getDefault().register(this);
        getWindow().setStatusBarColor(Color.TRANSPARENT);
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onReceiveEvent(CustomEvent event) {

    }

    protected abstract void initData();

    protected abstract void initView();

    protected abstract Class<VM> getViewModel();

    protected abstract int getLayoutId();
}
